var token=(new parent.window._user()).getData('token');
var userFun = new _user();
layui.define(["form","jquery"],function(exports){
	    var form = layui.form,
	    $ = layui.jquery,
	    Menu = function(){};

    Menu.prototype.provinces = function() {
        //加载厂家数据
        var proHtml = '',that = this;
        $.get('/dictionarygroup/vender?_token='+token, function (result) {
            var data=result.data;
            for (var i = 0; i < data.length; i++) {

                proHtml += '<option value="' + data[i].code + '">' + data[i].name + '</option>';
            }
            //初始化厂家数据
            $("select[name=vender]").append(proHtml);
            form.render();
            var hasChilds=data[0].childs;
            if(hasChilds){
                that.systems(hasChilds);
                userFun.setData('venderCode', data[0].code);
            }
            form.on('select(vender)', function (proData) {
                var venderCode = proData.value;
                userFun.setData('venderCode', venderCode);
                var childs = data[$(this).index()].childs;
                if (childs) {
                    that.systems(childs);
                } else {
                    $("select[name=system]").attr("disabled", "disabled");
                }
            });
        })
    }

    //加载系统数据
    Menu.prototype.systems = function(systems) {
        var systemHtml = '',that = this;
        for (var i = 0; i < systems.length; i++) {
            systemHtml += '<option value="' + systems[i].code + '">' + systems[i].name + '</option>';
        }
        $("select[name=system]").html(systemHtml).removeAttr("disabled");
        form.render();
        var hasChilds=systems[0].childs;
        if(hasChilds){
            userFun.setData('productCode', systems[0].code);
            that.versions(hasChilds);
        }
        form.on('select(system)', function (systemData) {
            var productCode = systemData.value;
            userFun.setData('productCode', productCode);
            var childs = systems[$(this).index()].childs;
            if (childs) {
                that.versions(childs);
            } else {
                $("select[name=version]").attr("disabled", "disabled");
            }
        });
    }

    //加载版本数据
    Menu.prototype.versions = function(versions) {
        var versionHtml = '';
        for (var i = 0; i < versions.length; i++) {
            versionHtml += '<option value="' + versions[i].code + '">' + versions[i].name + '</option>';
        }
        $("select[name=version]").html(versionHtml).removeAttr("disabled");
        form.render();
        if(versions.length>0){
            userFun.setData('versionCode', versions[0].code);
        }else {
            userFun.setData('versionCode', '');
        }
        form.on('select(version)', function (versionData) {
            var versionCode=versionData.value
            userFun.setData('versionCode', versionCode);
        });
    }

    var menu = new Menu();
    exports("threeselect",function(){
        menu.provinces();
    });
});
		